package com.yunkazaixian.syntelecom.controller;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;

@Controller
@RequestMapping("gen")
public class Generate {

    @RequestMapping("gen")
    @ResponseBody
    public String genfromDb(){

        String tb="mc_call_phone_setting";
        String dir_name="D://gen";
        //String dirName="/Users/lin/Downloads/";
        FastAutoGenerator.create("jdbc:mysql://rm-2zep97f892i76zk8eio.mysql.rds.aliyuncs.com:3306/llk?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false", "qo0gph8uffrsdh7zx2fbk", "OY2GglSNjLCSNkO9dAuAt")
                .globalConfig(builder -> {
                    builder.author("Guo") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .dateType(DateType.ONLY_DATE)
                            .outputDir(dir_name); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.yunkazaixian") // 设置父包名
                            .moduleName("syntelecom") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, dir_name)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tb); // 设置需要生成的表名
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

        return "success";
    }

}
